package com.lagou.edu.utils;

import com.lagou.edu.annotation.ZdyAutowired;
import com.lagou.edu.annotation.ZdyService;
import com.lagou.edu.annotation.ZdyTransactional;

import java.sql.SQLException;

/**
 * @author 应癫
 *
 * 事务管理器类：负责手动事务的开启、提交、回滚
 */
@ZdyService("transactionManager")
public class TransactionManager {

    @ZdyAutowired
    private ConnectionUtils connectionUtils;

    public void setConnectionUtils(ConnectionUtils connectionUtils) {
        this.connectionUtils = connectionUtils;
    }

    //开启事务（将自动提交关闭）
    public void beginTransacation() throws SQLException {
        connectionUtils.getCurrentThreadConn().setAutoCommit(false);
    }
    //提交
    public void commit() throws SQLException {
        connectionUtils.getCurrentThreadConn().commit();
    }
    //回滚
    public void rollback() throws SQLException {
        connectionUtils.getCurrentThreadConn().rollback();
    }


}
